﻿using Microsoft.Extensions.DependencyInjection;
using Modules.Project.Repositories;
using PmSoft;

namespace Modules.Project;

/// <summary>
/// 项目状态变更记录表服务
/// </summary>
[UseDI(ServiceLifetime.Scoped)]
public class ProjectStatusChangeRecordService
{
    private readonly ProjectStatusChangeRecordRepository projectStatusChangeRecordRepository;

    public ProjectStatusChangeRecordService(ProjectStatusChangeRecordRepository projectStatusChangeRecordRepository)
    {
        this.projectStatusChangeRecordRepository = projectStatusChangeRecordRepository;
    }

    public IEnumerable<ProjectStatusChangeRecord> GetProjectStatusChangeRecordsByProjectId(int projectId)
    {
        return projectStatusChangeRecordRepository.GetProjectStatusChangeRecordsByProjectId(projectId);
    }

    /// <summary>
    /// 项目状态变更记录表表单详情
    /// </summary>
    /// <param name="id">主键</param>
    /// <returns></returns>
    public ProjectStatusChangeRecord? Get(int id)
    {
        return projectStatusChangeRecordRepository.Get(id);
    }

    /// <summary>
    /// 批量删除，根据id
    /// </summary>
    /// <param name="ids">id的集合</param>
    public void Deleted(IEnumerable<int> ids)
    {
        foreach (int id in ids)
        {
            Delete(id);
        }
    }

    /// <summary>
    /// 单个删除
    /// </summary>
    /// <param name="id">主键</param>
    public void Delete(int id)
    {
        projectStatusChangeRecordRepository.DeleteByEntityId(id);
    }

    /// <summary>
    /// 创建项目状态变更记录表
    /// </summary>
    /// <param name="entity">实体对象</param>
    public void Create(ProjectStatusChangeRecord entity)
    {
        projectStatusChangeRecordRepository.Insert(entity);
    }

    /// <summary>
    /// 编辑项目状态变更记录表
    /// </summary>
    /// <param name="entity">实体对象</param>
    public void Update(ProjectStatusChangeRecord entity)
    {
        projectStatusChangeRecordRepository.Update(entity);
    }

    public IEnumerable<ProjectStatusChangeRecord> GetProjectStatusChangeRecordsByProjectIds(IEnumerable<int> projectIds)
    {
        return projectStatusChangeRecordRepository.GetProjectStatusChangeRecordsByProjectIds(projectIds);
    }
}